package LearnDataStructure.a_线性结构.例题;

import java.util.EmptyStackException;
import java.util.Iterator;

/**
 * @version: 1.0
 * @Author: wuqiu
 * @date: 2023-07-04 18:57
 * @description: LeetcodeLearnAlgorithm -> LearnDataStructure.a_线性结构.例题
 */
public class j_构造队列使用两个栈 {
    public static void main(String[] args) {
        j_构造队列使用两个栈 test = new j_构造队列使用两个栈();
        test.enqueue(1);
        test.enqueue(2);
        test.enqueue(3);
        test.enqueue(4);
        test.enqueue(5);
        System.out.println(test.dequeue());
        System.out.println(test.dequeue());
        System.out.println(test.dequeue());
    }


    public MyStackList<Integer> stack1 = new MyStackList<Integer>();
    public MyStackList<Integer> stack2 = new MyStackList<Integer>();

    public void enqueue(int element) {
        if (stack1.empty()) {
            moveStack(stack2,stack1);
        }
        stack1.push(element);
    }

    public int dequeue() {
        if (stack2.empty()) {
            moveStack(stack1,stack2);
        }
        return stack2.pop();
    }

    public void moveStack(MyStackList<Integer> source, MyStackList<Integer> target) {
        while (!source.empty()) {
            target.push(source.pop());
        }
    }
}
